package producer_consumer;

public class Consumer implements Runnable {

    @Override
    public void run() {
        while (true) {
            WareHouse.lock.lock();
            if(WareHouse.mark){
                //有包子就吃，吃完唤醒生产者
                System.out.println("消费者吃包子");
                WareHouse.mark = false;
                WareHouse.producer.signal();
            }else{
                //没包子,等
                try {
                    WareHouse.consumer.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }
            WareHouse.lock.unlock();
        }
    }
}
